﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinForm_Mes.CheckManagement
{
    public partial class CheckStandardForm : DevExpress.XtraEditors.XtraForm
    {
        public CheckStandardForm()
        {
           
            InitializeComponent();
            this.Load +=  CheckStandardForm_Load;
        }

        private int pageIndex = 1;
        private int pageSize = 10;
        //总条数
        public int total;
        /// <summary>
        /// 分页结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public class PageResult<T>
        {
            public int total { get; set; }
            public int pageIndex { get; set; }
            public int pageSize { get; set; }
            public List<T> items { get; set; }
            public int code { get; set; }
            public string message { get; set; }
            public object data { get; set; }
        }
        public class CheckStandardDto
        {
            public string checkCode { get; set; }

            public string checkName { get; set;}

            public string checkWay { get; set;}

            public string productCategory { get; set;}

            public string checkVersion { get; set;}

            public string gProcessId { get; set;}

            public string gProcessName { get; set;}

            public bool isEnabled {  get; set; }

            public int sampleCount { get; set;}
        }

        public async Task LoadDataAsync()
        {
            string code = CheckCodeText.Text.Trim();
            string name = ProcessNameText.Text.Trim();
            string url = $"http://localhost:5295/api/CheckStandard/GetAllCheckStandard?PageIndex={pageIndex}&PageSize={pageSize}&CheckCode={code}&ProcessName={name}";
            using(HttpClient client = new HttpClient())
            {
                var result = await client.GetFromJsonAsync<PageResult<CheckStandardDto>>(url);
                // 绑定 items 字段
                gridControl1.DataSource = result.items;
                 total = result.total;

            }
        }

        private async void CheckStandardForm_Load(object sender, EventArgs e)
        {
            await LoadDataAsync();
        }

        private void  checkButton2_Click(object sender, EventArgs e)
        {
            using (var addForm = new AddCheckStandardForm())
            {
                if (addForm.ShowDialog() == DialogResult.OK)
                {
                     LoadDataAsync(); // 新增成功后刷新列表
                }
            }
        }



        //private void checkButton2_CheckedChanged(object sender, EventArgs e)
        //{

        //}

        //private void gridControl1_Click(object sender, EventArgs e)
        //{

        //}
    }
}